// MFCWPFTESTView.cpp : implementation of the CMFCWPFTESTView class
//

#include "stdafx.h"
#include "MFCWPFTEST.h"

#include "MFCWPFTESTDoc.h"
#include "MFCWPFTESTView.h"
#include ".\mfcwpftestview.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CMFCWPFTESTView

IMPLEMENT_DYNCREATE(CMFCWPFTESTView, CView)

BEGIN_MESSAGE_MAP(CMFCWPFTESTView, CView)
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
	ON_WM_LBUTTONUP()
	ON_WM_MOUSEWHEEL()
	ON_WM_RBUTTONUP()
	ON_WM_RBUTTONDBLCLK()
	ON_WM_KEYUP()
	ON_WM_CHAR()
	ON_WM_LBUTTONDBLCLK()
END_MESSAGE_MAP()

// CMFCWPFTESTView construction/destruction

CMFCWPFTESTView::CMFCWPFTESTView()
{
	// TODO: add construction code here
	m_pMFCWPFInterface = NULL;
}

CMFCWPFTESTView::~CMFCWPFTESTView()
{
	if (m_pMFCWPFInterface)
	{
		delete m_pMFCWPFInterface;
		m_pMFCWPFInterface = NULL;
	}
}

BOOL CMFCWPFTESTView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CView::PreCreateWindow(cs);
}

// CMFCWPFTESTView drawing

void CMFCWPFTESTView::OnDraw(CDC* pDC)
{
	CMFCWPFTESTDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc)
		return;

	// TODO: add draw code for native data here
	m_pMFCWPFInterface->DrawSelf(pDC->GetSafeHdc());
}


// CMFCWPFTESTView printing

BOOL CMFCWPFTESTView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CMFCWPFTESTView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CMFCWPFTESTView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}


// CMFCWPFTESTView diagnostics

#ifdef _DEBUG
void CMFCWPFTESTView::AssertValid() const
{
	CView::AssertValid();
}

void CMFCWPFTESTView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CMFCWPFTESTDoc* CMFCWPFTESTView::GetDocument() const // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMFCWPFTESTDoc)));
	return (CMFCWPFTESTDoc*)m_pDocument;
}
#endif //_DEBUG


// CMFCWPFTESTView message handlers

void CMFCWPFTESTView::OnInitialUpdate()
{
	CView::OnInitialUpdate();

	// TODO: Add your specialized code here and/or call the base class
	m_pMFCWPFInterface = new CMFCWPFInterface;
	m_pMFCWPFInterface->AddFile(_XAMLFILEPATH1);
	m_pMFCWPFInterface->AddFile(_XAMLFILEPATH2);

/*	m_pMFCWPFInterface->Transform(_T("../PatientInfo/3CH_Format1.xml"));
	m_pMFCWPFInterface->Transform(_T("../PatientInfo/3CH_Format2.xml"));
	m_pMFCWPFInterface->Transform(_T("../PatientInfo/3CH_Format3.xml"));
	m_pMFCWPFInterface->Transform(_T("../PatientInfo/3CH_Format4.xml"));
	m_pMFCWPFInterface->Transform(_T("../PatientInfo/3CH_Format5.xml"));
	m_pMFCWPFInterface->Transform(_T("../PatientInfo/2CH_Format1.xml"));
	m_pMFCWPFInterface->Transform(_T("../PatientInfo/2CH_Format2.xml"));
	m_pMFCWPFInterface->Transform(_T("../PatientInfo/2CH_Format3.xml"));
	m_pMFCWPFInterface->Transform(_T("../PatientInfo/2CH_Format4.xml"));
	m_pMFCWPFInterface->Transform(_T("../PatientInfo/2CH_Format5.xml"));*/
	
	m_pMFCWPFInterface->AddFile(_T("../PatientInfo/3CH_Format1.xml.xaml"));
	m_pMFCWPFInterface->AddFile(_T("../PatientInfo/3CH_Format2.xml.xaml"));
	m_pMFCWPFInterface->AddFile(_T("../PatientInfo/3CH_Format3.xml.xaml"));
	m_pMFCWPFInterface->AddFile(_T("../PatientInfo/3CH_Format4.xml.xaml"));
	m_pMFCWPFInterface->AddFile(_T("../PatientInfo/3CH_Format5.xml.xaml"));
	m_pMFCWPFInterface->AddFile(_T("../PatientInfo/2CH_Format1.xml.xaml"));
	m_pMFCWPFInterface->AddFile(_T("../PatientInfo/2CH_Format2.xml.xaml"));
	m_pMFCWPFInterface->AddFile(_T("../PatientInfo/2CH_Format3.xml.xaml"));
	m_pMFCWPFInterface->AddFile(_T("../PatientInfo/2CH_Format4.xml.xaml"));
	m_pMFCWPFInterface->AddFile(_T("../PatientInfo/2CH_Format5.xml.xaml"));
}

void CMFCWPFTESTView::OnLButtonUp(UINT nFlags, CPoint point)
{
	// TODO: Add your message handler code here and/or call default
	if (m_pMFCWPFInterface->MouseLeftButtonUp(nFlags, point, this))
	{
		Invalidate(TRUE);
	}

	CView::OnLButtonUp(nFlags, point);
}

BOOL CMFCWPFTESTView::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
{
	// TODO: Add your message handler code here and/or call default
	if (zDelta >= 120)
	{
		m_pMFCWPFInterface->ChangeRatio(0.1f, 0.1f);
	}
	else
	{
		m_pMFCWPFInterface->ChangeRatio(-0.1f, -0.1f);
	}
	Invalidate(TRUE);

	return CView::OnMouseWheel(nFlags, zDelta, pt);
}

void CMFCWPFTESTView::OnRButtonUp(UINT nFlags, CPoint point)
{
	// TODO: Add your message handler code here and/or call default

	CView::OnRButtonUp(nFlags, point);
}

void CMFCWPFTESTView::OnRButtonDblClk(UINT nFlags, CPoint point)
{
	// TODO: Add your message handler code here and/or call default
	m_pMFCWPFInterface->PageUp();
	Invalidate(TRUE);

	CView::OnRButtonDblClk(nFlags, point);
}

void CMFCWPFTESTView::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags)
{
	// TODO: Add your message handler code here and/or call default

	CView::OnKeyUp(nChar, nRepCnt, nFlags);
}

void CMFCWPFTESTView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
	// TODO: Add your message handler code here and/or call default
	switch (nChar)
	{
	case '1':
		m_pMFCWPFInterface->TurnToNumber(1);
		break;

	case '2':
		m_pMFCWPFInterface->TurnToNumber(2);
		break;

	case '3':
		m_pMFCWPFInterface->TurnToNumber(3);
		break;

	default:
		break;
	}
	Invalidate(TRUE);

	CView::OnChar(nChar, nRepCnt, nFlags);
}

void CMFCWPFTESTView::OnLButtonDblClk(UINT nFlags, CPoint point)
{
	// TODO: Add your message handler code here and/or call default
	m_pMFCWPFInterface->PageDown();
	Invalidate(TRUE);

	CView::OnLButtonDblClk(nFlags, point);
}
